FUNCTIONAL PEARLS Drawing Trees
نویسندگان
چکیده
This article describes the application of functional programming techniques to a problem previously studied by imperative programmers, that of drawing general trees automatically. We first consider the nature of the problem and the ideas behind its solution (due to Radack), independent of programming language implementation. We then describe a Standard ML program which reflects the structure of the abstract solution much better than an imperative language implementation. We conclude with an informal discussion on the correctness of the implementation and some changes which improve the algorithm’s worst-case time complexity. 1 The problem and its solution The problem is this: given a labelled tree, assign to each node a position on the page to give an aesthetically pleasing rendering of the tree. We assume that nodes at the same depth are positioned on the same horizontal line on the page, so the problem reduces to finding a position horizontally for each node. But what do we mean by “aesthetically pleasing”? The various papers on the subject (Radack, 1988; Wetherell and Shannon, 1979; Vaucher, 1980; Reingold and Tilford, 1981; Walker, 1990) list aesthetic rules which constrain the positions in a number of ways. We adopt the same rules as Radack and Walker: 1. Two nodes at the same level should be placed at least a given distance apart. 2. A parent should be centred over its offspring. 3. Tree drawings should be symmetrical with respect to reflection—a tree and its mirror image should produce drawings that are reflections of each other. In particular, this means that symmetric trees will be rendered symmetrically. So, for example, Figure 1 shows two renderings, the first bad, the second good. 4. Identical subtrees should be rendered identically—their position in the larger tree should not affect their appearance. In Figure 2 the tree on the left fails the test, and the one on the right passes. Finally, trees should be as narrow as possible without violating these rules. 528 Andrew J. Kennedy
منابع مشابه
A New Heuristic Algorithm for Drawing Binary Trees within Arbitrary Polygons Based on Center of Gravity
Graphs have enormous usage in software engineering, network and electrical engineering. In fact graphs drawing is a geometrically representation of information. Among graphs, trees are concentrated because of their ability in hierarchical extension as well as processing VLSI circuit. Many algorithms have been proposed for drawing binary trees within polygons. However these algorithms generate b...
متن کاملSpecial issue on functional pearls Editorial
You are holding a necklace in your hands, composed of no fewer than thirteen exquisite pearls. The pearls are from all over the world, selected for the finest quality, smoothness and lustre. For your viewing pleasure, the necklace emphasizes variety, stringing pearls of wildly different color, shape and size. Satisfaction is guaranteed. This special issue of the Journal of Functional Programmin...
متن کاملPearltrees as a tool for referencing and teaching
Pearltrees is a social service, using which people can organise Web contents, photos and notes. These contents are the “pearls” on some trees. Besides the social opportunities, the trees can be used as a tool to organise references and for content curation. However, they can be helpful for teaching purposes too.
متن کاملArea-eecient Algorithms for Upward Straight-line Tree Drawings ?
In this paper, we investigate planar upward straight-line grid drawing problems for bounded-degree rooted trees so that a drawing takes up as little area as possible. A planar upward straight-line grid tree drawing satisses the following four constraints: (1) all vertices are placed at distinct grid points (grid), (2) all edges are drawn as straight lines (straight-line), (3) no two edges in th...
متن کاملProbabilistic analysis of the asymmetric digital search trees
In this paper, by applying three functional operators the previous results on the (Poisson) variance of the external profile in digital search trees will be improved. We study the profile built over $n$ binary strings generated by a memoryless source with unequal probabilities of symbols and use a combinatorial approach for studying the Poissonized variance, since the probability distribution o...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 1995